<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>js案例1</title>
	</head>
	<body>
		<button type="button"  onclick="myfunction('xieyingeng','xuesheng')">点我一下</button>
		<button onclick="myFunction('Harry Potter','Wizard')">点击这里</button>
		<button type="button" onclick="document.getElementById('demo').innerHTML=Date()">现在时间是？</button>
		<p id="demo"></p>
		<p  onmousedown="colors(this,'red')" onmouseup="colors(this,'green')">我是谢应鹏呀</p>
		
		<script type="text/javascript">
			/* document.write('xieyingepng');
			var a = 100;
			console.log(0xa)//0x开头表示16进制  以0开头的是8进制   以0b开头的表示二进制
			console.log(typeof a.toString());//类型转换
			console.log(typeof a);//输出a的类型
			console.log(Number.MAX_VALUE);//输出数值 表示的最大值
			var b = NaN;
			console.log(b);
			console.log(typeof b); 
			var  a = true;//布尔值  true false 
			console.log(typeof a);
			console.log(typeof null);//返回一个空的object对象
			console.log(true+1);//结果为2
			console.log(true);//结果为1
			console.log(true+false);//结果为1
			console.log(2+NaN);//结果为NaN */
			/* 对象 */
			function myfunction(name,job){
				alert("welcome"+name+"the"+job);
			}
			function myFunction(name,job){
				alert("Welcome " + name + ", the " + job);
			}
			function  colors(elmt,colre){
				elmt.style.color=colre;
			}
			function cuo(){
				try{
					alter('nh');
				} 
				catch(err){
					var text = '网页有一个错误为:'+err.message;
					alert(text);
				}
			}
			
			function f(){//表单验证
				var x = document.forms["myForm"]["fname"].value;
				if(x == null || x == ""){
					alert("请输入姓名");
					return false ;
				}
			}
			function numbers(){
				var text ,x ;
				x = document.getElementById("numb").value;
				if(isNaN(x) || x < 1 || x > 10){
					text = "输入错误";
				} else {
					text = "输入正确";
				}
				document.getElementById("texts").innerHTML = text;
			}
			function emialss(){
				var x = document.forms["xie"]["ying"].value;
				var y = x.indexOf("@");
				var z = x.lastIndexOf(".");
				if(y<1 || z<y+2 || z+2>=x.length){
					alert("不是一个合法的电子邮件");
					return false;
				}
			}
			function validateForm(){
				var x=document.forms["myForm"]["email"].value;
				var atpos=x.indexOf("@");
				var dotpos=x.lastIndexOf(".");
				if (atpos<1 || dotpos<atpos+2 || dotpos+2>=x.length){
					alert("不是一个有效的 e-mail 地址");
			  		return false;
				}
			}
			function yanz(){
				var x = document.getElementById("id1");
				var txt = '';
				if(x.validity.rangeOverflow){
					txt="你输入的值大了";
				}
				document.getElementById("demo").innerHTML = txt;
			}
			function myFunction() {
			    var txt = "";
			    if (document.getElementById("id1").validity.rangeOverflow) {
			       txt = "输入的值太大了";
			    }
			    document.getElementById("demo").innerHTML = txt;
			}
			var h = 10 ;
			{//代码块作用
				let h = 20 ;
				console.log(h);
			}
			console.log(h);
			function print(){
				document.getElementById('deo').innerHTML = '你好呀';
			}
			setTimeout(print,3000);//两种的写法一样
			setTimeout(function(){
				document.getElementById('deo').innerHTML = '谢应鹏';
			},3000);
			function suns( a, b){
				return a+b;
			}
			console.log(suns(3,5));
			var myfunction   = new Function("a","b","return a*b");
			document.getElementById("deo").innerHTML = myFunction(3,4);
			var myFunction = new Function("a", "b", "return a * b");
			document.getElementById("deo").innerHTML = myFunction(4, 3);
			myfun(6);
			function myfun(y){
				return y*y;
			}
			(function(){
				console.log('nh');
			})();
			(function () {
			    document.getElementById("deo").innerHTML = "Hello! 我是自己调用的";
			})();
			const x = (x,y) =>x*y;
			console.log(x);
		</script>
		<form  method="post" name="xie" onsubmit="return f() " 
		action="demo_form.php">
			姓名：<input type="text" name="ying"  />
			<input type="submit"  value="提交"  />
		</form>
		<form action="" method="post"><!-- 自动验证表单 -->
			<input type="text" name="fname" id="" value="" required="required"/>
			<input type="submit" name="" id="" value="提交" />
		</form>
		<form action="" method="post" name="xie" onsubmit="return emialss()">
			emial:<input type="text" name="ying"/>
			<input type="submit"  value="提交" />
		</form>
		<form name="xie" action="demo-form.php" onsubmit="return  emialss();" method="post">
		Email: <input type="text" name="ying">
		<input type="submit" value="提交">
		</form>
		<p>输入1-10的数字</p>
		<input id="numb" />
		<button type="button" onclick="numbers()">提交</button>
		<p id="texts"></p>
		<!-- <input type="number"  id="id1"  max="100" />
		<button type="button" onclick="yanz()">验证</button>
		<p id="demo"></p> -->
		<input id="id1" type="number" max="100">
		<button onclick="myFunction()">验证</button>
		<p id="demo">定位</p>
		<a href="#id2">定位</a>
	
		<a href="javascript:void(alert('Warning!!!'))">点我!</a>
		
<!-- 		<p id="id2" style="padding-top: 500px;">你好</p>

 -->	
		<p>3秒之后执行</p>
		<p id="deo"></p>
 
	</body>
</html>
